import { http } from "@/utils/http";

// 获取会刊列表返回类型
export type ExhibitionListResult = {
  code: number;
  msg: string;
  time: string;
  data: ExhibitionListData;
};

// 会刊列表data数据类型
export type ExhibitionListData = {
  total: number;
  page: number;
  limit: number;
  list: ExhibitionListDataItem[];
};

// 会刊列表data数据类型
export type ExhibitionListDataItem = {
  id: number;
  logo: string;
  company_name_cn: string;
  company_name_en: string;
  addres_cn: string;
  addres_en: string;
  phone: string;
  email: string;
  telephone: string;
};

// 获取会刊列表
export const getExhibitionList = (page = 1, limit = 10, exhibitor_id?: number) => {
  return http.request<ExhibitionListResult>("get", "/api/journal/list", {
    params: {
      page,
      limit,
      exhibitor_id
    }
  });
};

// 提交会刊
export const submitExhibition = (data: any) => {
  return http.request("post", "/api/journal/apply", {
    data
  });
};

// 获取会刊详情
export const getExhibitionDetail = (id: number, exhibitor_id?: number) => {
  return http.request("get", "/api/journal/detail", {
    params: {
      id,
      exhibitor_id
    }
  });
};

// 更新会刊
export const updateExhibition = (data: any) => {
  return http.request("post", "/api/journal/update", {
    data
  });
};

// 更改会刊状态
export const updateExhibitionStatus = (id: number, exhibitor_id: number, status = 0) => {
  return http.request("post", "/api/journal/changeStatus", {
    data: {
      id,
      exhibitor_id,
      status
    }
  });
};

// 获取图片地址返回类型
export interface ImagePath {
  url: string;
  full_url: string;
}

// 上传图片
export const uploadImage = (file: File) => {
  const formData = new FormData();
  formData.append("file", file);

  return http.request("post", "/api/common/upload", {
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data" // 覆盖全局 application/json
    }
    // 不手动设置Content-Type，让浏览器自动设置multipart/form-data和boundary
  });
};
